<%@page import="bean.entity.Member"%>
<%@page import="bean.entity.DiscussContent"%>
<%@page import="java.util.TimeZone"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="bean.entity.Discussion"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../css/discussion/discussionContent.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script type="text/javascript" src="../js/discussion/discussionContent.js"></script>
</head>
<body>
	<%
		String memId = (String)session.getAttribute("memId");
	
		if (memId == null) {
	%>
	<table id="tableSendQuestion">
		<tr>
			<td>
				<textarea id="textareaSendQuestion" disabled="disabled">請於右上角登入後即可問問題</textarea>
			</td>
		</tr>
	</table>
	<%
		}
		else if (!memId.equals("0")) {
	%>
	<form id="formSendQuestion" method="post" action="./discussionContent">
		<table id="tableSendQuestion">
			<tr>
				<td>
					<textarea id="textareaSendQuestion" name="question">按這裡提出您的問題</textarea>
				</td>
			</tr>
			<tr>
				<td id="tdButtonAsk">
					<input id="submitAsk" class="hideButton" type="submit" value="提問" />
				</td>
			</tr>
		</table>
	</form>
	<%
		}
		
		List<Discussion> disList = (List<Discussion>)request.getAttribute("disList");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm");
		
		sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
		for (Discussion dis: disList) {
			List<DiscussContent> disContents = dis.getDiscussContents();
	%>
	<div class="discussionBlock">
		<%
			for (DiscussContent discussContent: disContents) {
				Member poMem = discussContent.getPoMember();
				
				if (poMem == null) {
		%>
		<span class="askName">鄭川如</span> 老師<br />
		<%
				}
				else {
		%>
		<span class="askName"><%=poMem.getName()%></span> 同學<br />
		<%
				}
				out.print(discussContent.getContent().getValue() + " " + sdf.format(discussContent.getTime()) + "<br /><br /><br />");
			}
		
			if (session.getAttribute("memId") == null) {
		%>
		<textarea class="answer" disabled="disabled">請於右上角登入後即可回答問題</textarea><br />
		<%
			}
			else {
		%>
		<form class="ans" method="post" action="./ansDiscuss">
			<textarea name="content" class="answer">按這裡回答問題</textarea><br />
			<input class="hideButton" type="submit" value="回答" />
			<input type="hidden" name="disId" value="<%=dis.getKey().getId()%>" />
		</form>
		<%
			}
		%>
	</div>
	<%
		}
	%>
</body>
</html>